﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T_Material.API.Application.Commands.PurchaseCommand;
using T_Material.API.Application.Commands.RequisitionCommand;
using T_Material.API.Application.Commands.StatisticsCommand;
using T_Material.Infrastructure.Interface;

namespace T_Material.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = nameof(ApiversionInfo.物资领用))]
    public class RequisitionAPIController : ControllerBase
    {
        private readonly IMediator mediator;
        public RequisitionAPIController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加物资领用
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> RequisitionAdd(RequisitionCreatedCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 添加物资领用提交审批
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> RequisitionAddState(RequisitionCreatedStateCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 删除物资领用
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> RequisitionDelete([FromQuery] RequisitionDeleteCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 修改物资领用
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> RequisitionUpdate(RequisitionUpdateCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 修改物资采购状态
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> RequisitionUpdateState(RequisitionUpdateStateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 修改物资采购状态审批
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> RequisitionUpdateStateShenPi(RequisitionUpdateStateShenPiCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 批删物资领用
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> RequisitionDels([FromQuery] RequisitionDelsCommand command)
        {
            try
            {
                return await mediator.Send(command);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
